package com.wzk.canalsync.config;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;

/**
 * @Author: WangZiKang
 * @Date: 2024/12/29 12:02
 */

@Configuration
@ConfigurationProperties(prefix = "canal")
@Getter
@Setter
public class CanalConfig {

    private String host;

    private Integer port;

    private String username;

    private String password;

    private String destination;

    @Bean
    public CanalConnector canalConnector(){
        //判断是否设置了账号密码
        if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)){
            CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(host,port), destination, username, password);
            return connector;
        }
        //没有账号密码
        CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(host, port), destination,"","");
        return connector;
    }



}
